package com.knife.blog.logic.impl;

import java.util.ArrayList;
import java.util.Collection;
import com.knife.blog.domain.BlogCircleMember;
import com.knife.blog.domain.BlogInfo;
import com.knife.blog.domain.BlogUser;
import com.knife.blog.logic.BlogCircleMemberService;
import com.knife.blog.logic.BlogUserService;
import com.knife.web.tools.DbPageList;
import com.knife.web.tools.IPageList;

public class BlogCircleMemberServiceImpl extends DAOSupportService implements BlogCircleMemberService {

	private static BlogCircleMemberServiceImpl circleMemberService = new BlogCircleMemberServiceImpl();
	
	private BlogUserService userService = BlogUserServiceImpl.getInstance();
	
	public boolean delCircleMember(String cid) {
		// TODO 自动生成方法存根
		return this.dao.del(getCircleMember(cid));
	}

	public BlogCircleMember getCircleMember(String cid) {
		// TODO 自动生成方法存根
		BlogCircleMember member = (BlogCircleMember)this.dao.get(BlogCircleMember.class, cid);
		return member;
	}
	
	public BlogCircleMember getCircleMemberByUserName(String username){
		BlogCircleMember member = (BlogCircleMember)this.dao.getBy(BlogCircleMember.class, "inputuser", username);
		return member;
	}

	public boolean lockCircleMember(String cid) {
		// TODO 自动生成方法存根
		return false;
	}

	public IPageList queryCircleMember(String scope,Collection paras,int currentPage, int pageSize) {
		DbPageList pList = new DbPageList(BlogCircleMember.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}
	
	public IPageList queryCircleMemberByCircleCid(String cid,int currentPage, int pageSize){
		String scope = "sn=?";
		Collection<Object> paras = new ArrayList<Object>();
		paras.add(cid);
		return queryCircleMember(scope,paras,currentPage,pageSize);
	}
	
	public IPageList queryNewCircleMember(String cid, int currentPage, int pageSize){
		String scope = "sn=? order by inputtime desc";
		Collection<Object> paras = new ArrayList<Object>();
		paras.add(cid);
		return queryCircleMember(scope,null,currentPage,pageSize);
	}
	
	public IPageList queryAuditingCircleMember(String cid, int currentPage, int pageSize){
		String scope = "sn=? and status=0";
		Collection<Object> paras = new ArrayList<Object>();
		paras.add(cid);
		return queryCircleMember(scope,paras,currentPage,pageSize);
	}
	
	public IPageList queryCircleMember(int currentPage, int pageSize){
		String scope = "1=1";
		return queryCircleMember(scope,null,0,-1);
	}

	public static BlogCircleMemberService getInstance() {
		// TODO 自动生成方法存根
		return circleMemberService;
	}

	public boolean save(BlogCircleMember member){
		boolean ret;
		ret = this.dao.save(member);
		return ret;
	}
	
	public boolean update(BlogCircleMember member) {
		// TODO 自动生成方法存根
		boolean ret = this.dao.update(member);
		return ret;
	}
	
	public BlogCircleMember blogUser2BlogCircleMember(BlogUser user){
		String username = user.getUsername();
		BlogCircleMember member = new BlogCircleMember();
		BlogInfo blog = userService.getUserBlog(username);
		member.setInputuser(username);
		member.setUrl(blog.getDomain());
		return member;
	}

	

}
